$(document).ready(function() {
	logic.initi();
});

var logic = {
	fileSelectArea : null,
	upload_area : null,
	currentIframe : null,
	
	initi : function() {
		this.fileSelectArea =  document.getElementById("file_select_area");
		this.upload_area =  document.getElementById("file_select_area");
		this.createIframe();
	},
	
	handleSubmit : function(form, id) {
		var guiObject;

		this.currentIframe.style.height = "0px";		
		guiObject = this.showLinkAndProgress(form);
		guiObject.id = id;
		newFilehandler(guiObject);
		this.createIframe();
	},
	
	showLinkAndProgress : function(form) {
		var item = document.createElement("div"),
			left = document.createElement("div"),
			right = document.createElement("div"),
			innerLeft = document.createElement("div"),
			innerRight = document.createElement("div"),
			abort = document.createElement("input");
			progressbar = document.createElement("div"),
			progress = document.createElement("div"),
			progresstext = document.createElement("p"),
			linktext = document.createElement("p");
		
		abort.type = "button";
		abort.value = "Abort";
		
		linktext.className = "linktext";
		item.className = "item";
		abort.className = "abort";
		innerLeft.className = "left";
		innerRight.className = "right";
		left.className = "left";
		right.className = "right";
		progress.className = "right progress";
		progresstext.className = "progresstext"
		progressbar.className = "progressbar";
		
		innerLeft.appendChild(progressbar);
		innerLeft.appendChild(progresstext);
		innerRight.appendChild(abort);
		progress.appendChild(innerLeft);
		progress.appendChild(innerRight);
		left.appendChild(linktext);
		right.appendChild(progress);
		item.appendChild(left);
		item.appendChild(right);
		this.upload_area.appendChild(item);
		
		return { progressbar : progressbar,
			     progresstext : progresstext,
			     abort : abort,
			     iframe : this.currentIframe,
			     form : form,
			     linktext : linktext,
			     item : item};
	},
	
	createIframe : function() {
		this.currentIframe = document.createElement("iframe");
		this.currentIframe.src = "iframe.html";
		this.currentIframe.className = "fileselector";
		this.fileSelectArea.appendChild(this.currentIframe);
	}
}